﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using QuestionStuff;

[ExecuteInEditMode]
public class GUIClass : Networking
{
    QuestionGenerator q = new QuestionGenerator();
    string questionString;
    List<float> answers = new List<float>();
    void Start()
    {
		base.Start ();
        GenerateNewQuestion();
    }
    public int EnemiesKilled
    {
        get;
        set;
    }
    void GenerateNewQuestion()
    {

        questionString = q.QuestionBuilder(2);
        answers = q.AnswerGenerator(Random.Range(2,8));
    }
    void OnGUI()
    {
        float width = Screen.width * 0.8f;
        GUI.BeginGroup(new Rect(Screen.width * 0.1f, 0, width, Screen.height * 0.5f));
        GUI.Box(new Rect(0, 0, width, Screen.height * 0.3f), questionString, UIBox);
        GUI.Box(new Rect(0, Screen.height * 0.3f, width, Screen.height * 0.1f), "Enemies Killed : " + EnemiesKilled.ToString(),UIBox);
        for (int i = 0; i < answers.Count; i++)
        {
            if (GUI.Button(new Rect((int)(width * 0.1f) + i * ((width * 0.8f) / answers.Count ), Screen.height * 0.1f, (width * 0.8f) / answers.Count, Screen.height * 0.15f), answers[i].ToString(),customSkin.button))
            {
                GameObject player = GameObject.FindGameObjectWithTag("Player");
                if (answers[i] == q.CorrectAnswer)
                {
                    GenerateNewQuestion();
                    player.GetComponent<PlayerFight>().PlayerAttack();
                }
                else
                {
                    player.GetComponent<HealthBar>().Health--;
                }
            }
        }
       
        GUI.EndGroup();
       
    }

}